package yyee.llee.mmee.weather.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import yyee.llee.mmee.base_api_net.base_api_bean.bean.Citys
import yyee.llee.mmee.common.databinding.ItemSearchingBinding

class SearchAdapter(
    private val mContext: Context,
    private val data: List<Citys>,
    private val onCityChecked: (Citys) -> Unit,
) : RecyclerView.Adapter<SearchAdapter.ViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, i: Int): ViewHolder {
        return ViewHolder(
            ItemSearchingBinding.inflate(LayoutInflater.from(mContext), parent, false)
        )
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val item = data[position]
        holder.binding.tvCity.text = item.district
        holder.itemView.setOnClickListener {
            onCityChecked(item)
        }
    }

    override fun getItemCount(): Int {
        return data.size
    }

    class ViewHolder(val binding: ItemSearchingBinding) :
        RecyclerView.ViewHolder(binding.root)
}